<?php $this->registerResourcePackage('bootstrapDatetimepicker')?>
<?php $this->registerResourcePackage('bootstrapSelect')?>
<?php
$Y = ! empty ( $value ) ? date ( 'Y', $value ) : '';
$M = ! empty ( $value ) ? date ( 'm', $value ) : '';
$D = ! empty ( $value ) ? date ( 'd', $value ) : '';
function to00($i) {
	return substr ( '00' . $i, - 2, 2 );
}
$date = !empty($value)?date('d-m-Y', $value):'';
?>

<div class="form-group">
	<label class="col-sm-3 control-label"><?php echo $params['label']; ?></label>
	<div class="col-sm-7 birthday-wrapper" data-date3f="<?php echo $params['name'] ?>"
		data-date3f-Y="<?php echo $params['name'] ?>_year"
		data-date3f-M="<?php echo $params['name'] ?>_month"
		data-date3f-D="<?php echo $params['name'] ?>_day"
		data-errors="<?php echo json_encode($errors)?>"
		>
		<input type="hidden" name="<?php echo $name ?>"
			value="<?=$date?>">

		<?php $wd = '30%' ?>
		<select data-date3f-D="true"
			data-width="<?php echo $wd ?>"
			class="selectpicker hidden-select"
			title="<?php echo 'Day'; ?>">
			<option></option>
			<?php for ($i=1;$i<=31;$i++) {?>
			<option <?=($i==$D?' selected':'')?>><?=to00($i)?></option>
			<?php } ?>
		</select>
		<div class="btn-group bootstrap-select selectpicker-bootafor" style="width: <?php echo $wd ?>">
			<button data-toggle="dropdown" class="btn dropdown-toggle selectpicker btn-default"
					type="button">
				<span class="filter-option pull-left"><?php echo $D; ?></span>&nbsp;<span class="caret"></span>
			</button>
		</div>

		<?php $wm = '36.5%' ?>
		<select title="<?php echo 'Month'; ?>" data-date3f-M="true"
			data-width="<?php echo $wm ?>"
			class="selectpicker hidden-select">
			<option></option>
			<?php for ($i=1;$i<=12;$i++) {?>
			<option value=<?=to00($i)?> <?=($i==$M?' selected':'')?>>
				<?php echo date('F', strtotime('2001-'.to00($i).'-20'));?>
			</option>
			<?php } ?>
		</select>
		<div class="btn-group bootstrap-select selectpicker-bootafor" style="width: <?php echo $wm ?>">
			<button data-toggle="dropdown" class="btn dropdown-toggle selectpicker btn-default"
					type="button">
				<span class="filter-option pull-left"><?php echo $M; ?></span>&nbsp;<span class="caret"></span>
			</button>
		</div>

		<?php $wy = '30%' ?>
		<select title="<?php echo 'Year'; ?>" data-date3f-Y="true"
			data-width="<?php echo $wy ?>"
			class="selectpicker hidden-select">
			<option></option>
			<?php for ($i=date('Y')-17;$i>1900;$i--) {?>
			<option <?=($i==$Y?' selected':'')?>><?=$i?></option>
			<?php } ?>
		</select>
		<div class="btn-group bootstrap-select selectpicker-bootafor" style="width: <?php echo $wy ?>">
			<button data-toggle="dropdown" class="btn dropdown-toggle selectpicker btn-default"
					type="button">
				<span class="filter-option pull-left"><?php echo $Y; ?></span>&nbsp;<span class="caret"></span>
			</button>
		</div>
	</div>

	<div class="col-sm-offset-3 col-sm-7">
		<div class="element-notice description"><?php echo $params['description']; ?></div>
		<div class="element-notice error"><?php echo implode(', ', $errors) ?></div>
	</div>
</div>
